package nina.yiyou.attendance.s10merge.output

import nina.yiyou.attendance.s10merge.compute.AttendDetailMerger
import nina.yiyou.salary.input.util.InputPathResolver

import java.nio.file.Path
import java.util.stream.Collectors

class MergeResultGenerator {

  MergeResultGenerator(Path workshopPath, List<AttendDetailMerger.DayResult> attendanceResult, Map<String, ?> globalResult) {
    _workshopPath = workshopPath
    _attendanceResult = attendanceResult
    _globalResult = globalResult
  }

  void generate() {
    Path outPath = InputPathResolver.create(_workshopPath, _globalResult, '全局.out.考勤明细').resolve()
//    println(outPath)

    List<Map> dayList = _attendanceResult.stream()
        .map { it.toMap() }
        .collect(Collectors.toList())

    List<String> keys = makeTemplateKeys()
    new ResultCsvExporter(outPath, dayList, keys).export()
  }

  /**
   * 明细表的列
   *
   * @see nina.yiyou.attendance.s10merge.compute.AttendDetailMerger#toDayMap
   */
  private List<String> makeTemplateKeys() {
    return [
        '明细.时间',
        '基本.工号',
        '明细.姓名',
        '基本.部门',
        '计算.上班',
        '计算.下班',
        '计算.时长',
        '计算.迟到线',
        '计算.迟到分钟',
        '计算.获得调休',
        '计算.忘打卡',
        '计算.加班',
//        '计算.餐补',
        '计算.试用应计',
        '计算.试用实计', // 试用期实际计薪小时数
        '计算.转正应计',
        '计算.转正实计', // 转正实际计薪小时数
        '请假.病假',
        '请假.事假',
        '请假.调休假',
        '请假.年假',
        '请假.产检假',
        '请假.产假',
        '请假.丧假',
        '请假.婚假',
        '请假.其他',
    ]
  }

  private final Path _workshopPath

  private final List<AttendDetailMerger.DayResult> _attendanceResult
  private final Map<String, ?> _globalResult
}
